/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package opennlp.wrappers;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import opennlp.tools.tokenize.Tokenizer;
import opennlp.tools.tokenize.TokenizerME;
import opennlp.tools.tokenize.TokenizerModel;

/**
 *
 * @author Luis A Riveros
 */
public class TokenizerW {

    private Tokenizer tokenizer;
    private OpenNLPModelsManager.LANGUAGE language;

    public TokenizerW(OpenNLPModelsManager.LANGUAGE language) {
        this.language = language;
        OpenNLPModelsManager modelsManager = OpenNLPModelsManager.getInstance();
        this.language = language;
        try {
            InputStream inputStream = modelsManager.loadModel(OpenNLPModelsManager.MODEL_TYPE.TOKENIZER, language);
            TokenizerModel tokenizerModel = new TokenizerModel(inputStream);
            tokenizer = new TokenizerME(tokenizerModel);
        } catch (FileNotFoundException fnfe) {
            Logger.getLogger(SentenceDetectorW.class.getName()).log(Level.SEVERE, "Model file not found", fnfe);
        } catch (IOException ioe) {
            Logger.getLogger(SentenceDetectorW.class.getName()).log(Level.SEVERE, "Error loading model", ioe);
        }
    }

    public String[] tokenize(String text) {
        return tokenizer.tokenize(text);
    }

    public String getLanguage() {
        return language.getName();
    }
}
